﻿using System.Windows.Forms;
using DataAccessLayer;
using Editor.Properties;

namespace Editor
{
    /// <summary>
    /// Form to set starting settings of a level
    /// </summary>
    public sealed partial class LevelSettingsForm : Form
    {
        public readonly GameLevel Level;
        
        public LevelSettingsForm(GameLevel level = null)
        {
            InitializeComponent();

            Level = level ?? new GameLevel();

            lvlStartTimeTxbx.Text = Level.StartTime.ToString();
        }

        private void lvlStartTimeTxbx_TextChanged(object sender, System.EventArgs e)
        {
            if (string.IsNullOrEmpty(lvlStartTimeTxbx.Text))
                return;

            try
            {
                Level.StartTime = float.Parse(lvlStartTimeTxbx.Text);
            } 
            catch
            {
                MessageBox.Show(Resources.LevelSettingNumericValueError,
                                Resources.LevelSettingErrorTitle);
            }
        }

        private void lvlOkBTn_Click(object sender, System.EventArgs e)
        {
            if (string.IsNullOrEmpty(lvlStartTimeTxbx.Text))
            {
                MessageBox.Show(Resources.LevelSettingOkBtnError,
                                Resources.LevelSettingErrorTitle);

                return;
            }

            DialogResult = DialogResult.OK;
            Close();
        }
    }
}
